package provisioner;

public class ComputeNode extends Resource {

   public static final int STOPPED = 0;
   public static final int STARTING = 1;
   public static final int STARTED = 2;
   public static final int READY = 3;
   public static final int STOPPING = 4;
   public static final int FAILED = 5;
   public static final int VPNNING = 6;
   public static final int CONTEXUALIZED = 7;

   private String hostname;
   private String ipAddress;
   private int state = STOPPED;   
   private long startTime;

   public ComputeNode(String id) {
      this(id,STOPPED);
   }

   public ComputeNode(String id,int state) {
      super(id);
      this.state = state;
      this.startTime = System.currentTimeMillis();
   }

   public synchronized void setState(int newState) {
      this.state = newState;
   }

   public synchronized int getState() {
      return this.state;
   }

   public synchronized void setHostname(String hostname) {
      this.hostname = hostname;
   }

   public synchronized String getHostname() {
      String hostname = this.hostname; 
      if (hostname == null) {
         hostname = this.ipAddress;
      }
      return hostname;
   }

   public synchronized void setIpAddress(String ipAddress) {
      this.ipAddress = ipAddress;
   }

   public synchronized String getIpAddress() {
      return this.ipAddress;
   }

   public synchronized long getStartTime() {
      return this.startTime;
   }

}
